package com.bozhao.zdy.starter.config;

import com.bozhao.zdy.starter.properties.CustomStarterProperties;
import com.bozhao.zdy.starter.service.CustomTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ZhaoBo (zhaobo@shanshu.ai)
 * @date 2022/3/10
 */
@Configuration
@ConditionalOnClass({ CustomTemplate.class})
@ConditionalOnBean(ConfigMarker.class)
@EnableConfigurationProperties(CustomStarterProperties.class)
public class CustomStarterAutoConfiguration {

    @Autowired
    private CustomStarterProperties customStarterProperties;

    @Bean
    @ConditionalOnMissingBean(CustomTemplate.class)
    public CustomTemplate getCustomStarterService() {
        CustomTemplate customTemplate = new CustomTemplate();
        customTemplate.setCode(customStarterProperties.getCode());
        customTemplate.setName(customStarterProperties.getName());
        return customTemplate;
    }
}
